package com.demo.producer;

import com.demo.common.Constant;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.common.message.Message;

import java.nio.charset.StandardCharsets;

/**
 * @author yexi
 */
public class OneWayProducer {
    public static void main(String[] args) throws Exception {
        DefaultMQProducer producer = new DefaultMQProducer(Constant.PRODUCER_GROUP_1);
        producer.setNamesrvAddr(Constant.ROCKET_MQ_ADDRESS);
        producer.start();
        String topic = "03-oneway";
        String tags = "tagA";
        String msg = "RocketMQ Oneway Send ";
        for (int i = 0; i < 100; i++) {
            Message message = new Message(
                    topic,
                    tags,
                    (msg + i).getBytes(StandardCharsets.UTF_8)
            );
            //一次性发送消息到一个Broker
            producer.sendOneway(message);
        }
        producer.shutdown();
    }
}